package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.BuildingBean;
import com.sx.zongzhi.modle.CollectManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IBuildingLayoutView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 * 楼宇布局添加
 */
public class BuildingLayoutAddPest {

    private IBuildingLayoutView layoutView;

    public BuildingLayoutAddPest(IBuildingLayoutView layoutView) {
        this.layoutView=layoutView;
    }


    /**
     * 生成楼宇布局
     * @param builddatasId 楼宇主键
     * @param row 行
     * @param column 列
     */
    public void addBuildingLayout(String builddatasId,int row, int column){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("builddatas.id", builddatasId);
        map.put("layoutRow",row);
        map.put("layoutColumn",column);
        new CollectManager().addBuildingLayout(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                layoutView.addBuildingLayout(response.getData());
            }
            @Override
            public void onFailures(String message) {
                layoutView.showError(message);
            }
        });
    }

    /**
     * 获取布局列表
     * @param id 楼宇主键
     */
    public void loadBuildLayoutList(String id){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("id", id);//楼宇主键
        new CollectManager().loadBuildLayoutList(map, new BaseCallBack<BaseResult<BuildingBean>>() {
            @Override
            public void onSuccess(BaseResult<BuildingBean> response) {
                layoutView.loadBuildLayoutList(response.getData());
            }
            @Override
            public void onFailures(String message) {
                layoutView.showError(message);
            }
        });
    }

    /**
     * 绑定楼宇
     * @param id 楼宇主键
     * @param houseId 房屋主键
     * @param layoutRow 绑定行
     * @param layoutColumn 绑定列
     */
    public void bindBuilding(String id,String houseId,int layoutRow,int layoutColumn){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("id",id);
        map.put("houseId",houseId);
        map.put("layoutRow",layoutRow);
        map.put("layoutColumn",layoutColumn);
        new CollectManager().bindBuilding(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                layoutView.bindBuilding(response.getData());
            }
            @Override
            public void onFailures(String message) {
                layoutView.showError(message);
            }
        });
    }
}
